package com.springboot.demo.autoconfig;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

@EnableConfigurationProperties(CustomProperties.class)
public class AutoConfig {
    @Bean
    public ApplicationListener<ApplicationReadyEvent> listener() {
        return event -> System.out.println("Catch Application Ready Event Successfully!");
    }

    @Bean
    @ConditionalOnProperty(prefix = "kenway.autoconfig", name = "enable", havingValue = "true")
    CommandLineRunner createCustomCommandLineRunner(Environment environment) {
        return new CustomCommandLineRunner(environment);
    }
}
